package oj.oj_145;

/**
 * 二叉树的后序遍历
 * https://leetcode.cn/problems/binary-tree-postorder-traversal/
 */

import oj.oj_144.TreeNode;

import java.util.*;

public class Solution {
    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        postInternal(root, ans);
        return ans;
    }

    private void postInternal(TreeNode root, List<Integer> ans) {
        if (root == null) {
            return;
        }

        postInternal(root.left, ans);
        postInternal(root.right, ans);
        ans.add(root.val);
    }
}
